using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace Scenario_Editor.WR2TerrainLoader
{
    internal class PointerTable
    {
        long startpositionOfBlock;
        List<uint> completePosition;
        List<uint> offsets;
        int sizeOfCollisionBlock;
        public void FromStream(BinaryReader br, int numberOfBlocks)
        {
            offsets = new List<uint>();
            completePosition = new List<uint>();
            this.startpositionOfBlock = br.BaseStream.Position;
            
            for (int i = 0; i < numberOfBlocks * 16; i++)
            {
                uint test = br.ReadUInt32();
                completePosition.Add(test + (uint)startpositionOfBlock);
                offsets.Add(test);
            }
        }
        public int StartpositionOfBlock
        {
            get
            {
                return (int)this.startpositionOfBlock;
            }
        }

        public List<uint> OffsetsCompletePosition
        {
            get
            {
                return this.completePosition;
            }
        }


        internal void Save(BinaryWriter bw, List<CollisionBlock> list, int numberOfBlocks)
        {
            uint offset = (uint)(numberOfBlocks * 16 * 4);
            this.offsets = new List<uint>();
            for (int i = 0; i < list.Count; i++)
            {
                this.offsets.Add((uint)(offset));
                offset += (uint)list[i].SizeInBytes;
            }

            for (int i = 0; i < this.offsets.Count; i++)
			{
                bw.Write(this.offsets[i]);
			}
        }
    }

}
